<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>节点操作-删除节点</title>
    <style>

    </style>
</head>

<body>
    <button>删除</button>
    <ul>
        <li>疾风剑豪</li>
        <li>无双剑姬</li>
        <li>暗裔剑魔</li>
        <li>无极剑圣</li>
        <li>石头人</li>
    </ul>
    <script>
        // 删除节点 node.removeChild(child)

        // 1.获取元素
        var ul = document.querySelector('ul');
        var btn = document.querySelector('button');
        // ul.children[0] //第一个子元素

        // 删除元素节点 node.removeChild(child)
        // ul.removeChild(ul.children[0]); //第一个
        // ul.removeChild(ul.children[ul.children.length - 1]); //最后一个
        btn.onclick = function() {
            // ul.removeChild(ul.children[0]);
            if (ul.children.length == 0) {
                this.disabled = true;
            } else {
                ul.removeChild(ul.children[0]);
            }

        }
    </script>
</body>

</html>